
using System.Xml;
using Mistral;
using Mistral.Xml;

namespace Conditions.Xml
{
	#region Condition_XmlNode_NameStartsWith

	public struct Condition_XmlNode_NameStartsWith : ICondition<XmlNode>
	{
		string m_nodeNamePart;

		public Condition_XmlNode_NameStartsWith( string nodeNamePart )
		{
			m_nodeNamePart = nodeNamePart;
		}

		#region ICondition<XmlNode> Members

		public bool Matches( XmlNode value )
		{
			return value.Name.StartsWith( m_nodeNamePart, XmlParser._nodeNameComparison );
		}

		#endregion
	}

	#endregion		
	#region Condition_XmlNode_AttrNameEquals

	public struct Condition_XmlNode_AttrNameEquals : ICondition<XmlNode>
	{
		string m_attrName;
		string m_attrValue;

		public Condition_XmlNode_AttrNameEquals( string attrName, string attrValue )
		{
			m_attrName = attrName;
			m_attrValue = attrValue;
		}

		#region ICondition<XmlNode> Members

		public bool Matches( XmlNode value )
		{
			string attrValue = XmlParser.GetAttrValue( value, m_attrName, string.Empty );
			return string.Compare( attrValue, m_attrValue, XmlParser._attrNameComparison ) == 0;
		}

		#endregion
	}

	#endregion
	#region Condition_XmlNode_AttrNameStartsWith

	public struct Condition_XmlNode_AttrNameStartsWith : ICondition<XmlNode>
	{
		string m_attrName;
		string m_attrValue;

		public Condition_XmlNode_AttrNameStartsWith( string attrName, string attrValue )
		{
			m_attrName = attrName;
			m_attrValue = attrValue;
		}

		#region ICondition<XmlNode> Members

		public bool Matches( XmlNode value )
		{
			string attrValue = XmlParser.GetAttrValue( value, m_attrName, string.Empty );
			return attrValue.StartsWith( m_attrValue );
		}

		#endregion
	}

	#endregion
}
